package com.yuqiao.read.design.observer;

public class CurrentConditionsDisplay implements IObserver ,DisplayElement {
    private float temperature;
    private float humidity;
    private ISubject subject;

    /**
     * 创建观察者并注册到发布中心
     * @param weatherData
     */
    public CurrentConditionsDisplay(ISubject weatherData){
        this.subject = weatherData;
        subject.registerObserver(this);
    }

    public void display() {
        System.out.println("當前觀測温度：="+temperature+"湿度：="+humidity);
    }

    /**
     * 一旦接到更改就设置更改并显示
     * @param temp
     * @param humidity
     * @param pressure
     */
    public void update(float temp, float humidity, float pressure) {
        this.temperature = temp;
        this.humidity = humidity;
        display();
    }
}
